package com.zzzzzz.account.service;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zzzzzz.account.dao.TicketDao;
import com.zzzzzz.account.model.Ticket;
import com.zzzzzz.common.id.UUIDGenerator;

@Service("ticketService")
public class TicketServiceImpl implements TicketService {

	@Resource
	private TicketDao ticketDao;

	public Ticket add(String classPK, String type, Date expirationDate) {
		Date now = new Date();

		Ticket ticket = new Ticket();
		ticket.setCreateDate(now);
		ticket.setClassPK(classPK);
		ticket.setType(type);
		ticket.setKey(UUIDGenerator.get());
		ticket.setExpirationDate(expirationDate);
		ticketDao.add(ticket);
		return ticket;
	}

	public Ticket findByKey(String key) {
		return ticketDao.findByKey(key);
	}
	
	public Ticket findByKeyAndType(String key, String type) {
		return ticketDao.findByKeyAndType(key, type);
	}
	
	public void delByKey(String key) {
		ticketDao.delByKey(key);
	}

}
